import random
import time

anim_dict = {}

# 得到随机动物的10个房间
def get_random_room():
    global anim_dict
    tiger = {"name": "老虎", "voice": "ヾ(≧O≦)〃嗷~...", "weight": 200, "food": "meet"}
    sheep = {"name": "小羊仔", "voice": "咩咩咩...", "weight": 100, "food": "grass"}
    for i in range(1, 11):
        anim_dict[i] = random.choice([tiger.copy(), sheep.copy()])

# 展示房间里面的动物
def show_room_anim():
    for key, val in anim_dict.items():
        print(f' {key} 号房间 = {val}')

#听房间动物声音
def hear_voice(door_num):
    anim = anim_dict[door_num]
    print(f'房间{door_num} : {anim["voice"]}')
    # 体重扣减5
    anim["weight"] -= 5
    anim_dict[door_num] = anim
    food = input(f'房间编号为:{door_num} ,请输入你的食物类型：')
    feed(door_num, food)

#投食
def feed(door_num, food):
    anim = anim_dict[door_num]
    if food == anim["food"]:
        print('小动物饱餐一顿....🤪🤪🤪')
        anim["weight"] += 10
    else:
        anim["weight"] -= 10
        print('喂养食物错误,一顿不能进食，瘦10斤....o(╥﹏╥)o')
    anim_dict[door_num] = anim


weight = 0
if __name__ == '__main__':
    print("游戏介绍：系统随机生成10个房间，每个房间存放2种动物老虎和小羊仔一种，其中老虎的体重是200斤，小羊仔的体重是100斤\n"
          "游戏开始会随机给10个房间并展示里面的动物,然后开始游戏，系统随机给出一个房间编号，根据自己的记忆或通过听声音喂食，"
          "其中投食错误惩罚小动物饿一顿扣减10斤,听声音也需要扣减5斤")
    print(
        "---------------------------------------------------------游戏介绍------------------------------------------------------")
    # 得到随机房间动物
    get_random_room()
    # 展示
    show_room_anim()

    print(
        "--------------------------------------------------------分割线--------------------------------------------------------")
    print("指令介绍：0.退出游戏 1.敲门听声音 meet(喂老虎) grass(喂小羊仔)")

    starttime = time.time()
    print("开始时间: ", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(starttime)))
    while 1:
        # 间隔时间
        interval = time.time() - starttime
        if interval >= 120:
            print("开始时间: ", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(starttime)))
            print("结束时间: ", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "interval", interval)
            print("时间到游戏结束！！！")
            break
        door_num = random.choice(range(1, 11))
        print("--------------------------------------------------------")
        oprt_num = input(f'房间编号为:{door_num} ,请输入你的操作：')
        if oprt_num == "1":
            #
            hear_voice(door_num)
        elif oprt_num == "meet":
            feed(door_num, oprt_num)
        elif oprt_num == "grass":
            feed(door_num, oprt_num)
        elif oprt_num == "0":
            print("游戏结束！！！")
            break
        else:
            print("错误操作！！！")

    print(
        "--------------------------------------------------------分割线--------------------------------------------------------")
    show_room_anim()
